/*
 * Proto Streamer
 * Copyright (C) 2009 John Pritchard.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */
package p.s.q;

import p.s.m.Service;
import alto.io.u.Array;
import alto.io.u.Lobjmap;
import java.util.Enumeration;
import java.util.Hashtable;
import java.lang.reflect.InvocationTargetException;

/**
 * Queue service manager.
 * 
 * @author jdp
 */
public final class Manager
    extends p.s.m.Manager
{

    public final static Manager Instance = new Manager();
    static {
        Instance.start();
    }
    public final static Queue Get(Object identity, Class<? extends Service> group){
        return (Queue)Instance.get(identity,group);
    }

    private final Hashtable<Class<? extends Queue>, Queue.Constructor> ctors;


    private Manager(){
        super();
        this.ctors = new Hashtable<Class<? extends Queue>, Queue.Constructor>();
    }


    public Queue newInstance(Object id, Class<? extends Service> group)
        throws NoSuchMethodException, InstantiationException, IllegalAccessException,
               IllegalArgumentException, InvocationTargetException
    {
        Class<? extends Queue> qgroup = (Class<? extends Queue>)group;
        Queue.Constructor ctor = this.ctors.get(qgroup);
        if (null == ctor){
            ctor = new Queue.Constructor(qgroup);
            this.ctors.put(qgroup,ctor);
        }
        return ctor.newInstance(id);
    }
}
